{include file='pub/header'/}
<title>订单列表</title>
<style>
    .td-manage a{
        display: inline-block;
    }
</style>
</head>

<body class="pos-r">
<nav class="breadcrumb">{$breadNav} <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
                                       href="javascript:location.replace(location.href);" title="刷新"><i
        class="Hui-iconfont">&#xe68f;</i></a></nav>
    <div class="page-container">
        <div class="text-c">
            <form action="" method="get">
                查询类型：
                <select name="searchKey" style="width:auto" class="select-box">
                    <option value="">未选择</option>
                    <option value="a.order_no" {if isset($param['searchKey']) && $param['searchKey'] eq 'a.order_no'}selected{/if}>订单编号</option>
                    <option value="a.order_no_pre" {if  isset($param['searchKey']) && $param['searchKey'] eq 'a.order_no_pre'}selected{/if}>支付订单号</option>
                    <option value="b.user_name" {if  isset($param['searchKey']) && $param['searchKey'] eq 'b.user_name'}selected{/if}>客户姓名</option>
                    <option value="b.telephone" {if  isset($param['searchKey']) && $param['searchKey'] eq 'b.telephone'}selected{/if}>客户手机号</option>
                </select>
                查询条件：
                <input type="text" autocomplete="off" name="searchValue" value="{$param.searchValue||default=''}" style="width:250px" class="input-text"/>
                {if isset($is_admin) && $is_admin eq 1}
                归属客服：
                <input type="text" name="agent_name" value="{$param.agent_name||default=''}" style="width:100px" class="input-text"/>
                {/if}
                订单状态：
                <select name="order_status" style="width: auto;" class="select-box">
                    <option value="">全部</option>
                    {foreach :config("order_status") as $key=>$val}
                    <option value="{$key}" {if isset($param['order_status']) && $param['order_status'] === "$key"}selected{/if}>{$val}</option>
                    {/foreach}
                </select>
                <label style="display: inline-block;">
                订单生成时间：
                <input type="text" autocomplete="off" value="{$param.start_time||default=''}" onfocus="WdatePicker({maxDate:'#F{ $dp.$D(datemax)}'})" id="datemin"
                       name="start_time" class="input-text Wdate" style="width:120px;">-
                <input type="text" autocomplete="off" value="{$param.end_time||default=''}" onfocus="WdatePicker({minDate:'#F{ $dp.$D(datemin)}'})" id="datemax"
                       name="end_time" class="input-text Wdate" style="width:120px;">
                </label>
                <button class="btn btn-success" type="submit">
                    <i class="Hui-iconfont">&#xe665;</i>查询
                </button>
            </form>
        </div>
        <div class="cl pd-5 bg-1 bk-gray mt-20">
            <span class="l">
                <a class="btn btn-primary radius" onclick="downloadOrder()" href="javascript:;">
                    <i class="Hui-iconfont">&#xe640;</i> 下载订单
                </a>
            </span>
        </div>
        <div class="mt-20">
            <table class="table table-border table-bordered table-bg table-hover table-sort">
                <thead>
                <tr class="text-c">
                    <th width="50">订单编号</th>
                    <th width="50">支付订单号<br><span style="font-size: 12px;">(作为财务审核订单用)</span></th>
                    <th width="60">下单时间</th>
                    <th width="60">下单客户</th>
                    <th width="60">客户ID</th>
                    <th width="60">归属客服</th>
                    <th width="30">订单状态</th>
                    <th width="30">支付方式</th>
                    <th width="30">商品总金额</th>
                    <th width="30">运费</th>
                    <th width="30">优惠金额</th>
                    <th width="60">支付总金额</th>
                    <th width="60">发货时间</th>
                    <th width="60">收货时间</th>
                    <th width="100">操作</th>
                </tr>
                </thead>
                <tbody>
                {foreach $list as $item}
                <tr class="text-c va-m">
                    <td>{$item.order_no}</td>
                    <td><b style="color: #F83B3C;">{$item.order_no_pre}</b></td>
                    <td>{$item.create_time}</td>
                    <td>{$item.user_name}</td>
                    <td>{$item.user_id}</td>
                    <td>{$item.agent_name}</td>
                    <td>
                        {if $item.refund_money eq $item.order_money || $item.refund_money eq $item.total_money}
                        已退款
                        {else}
                        {:config('order_status')[$item.order_status]}
                        {if $item.refund_money gt 0}
                        (已部分退款)
                        {/if}
                        {/if}
                    </td>
                    <td>{:config('pay_type')[$item.pay_type]}</td>
                    <td>{$item.total_money}</td>
                    <td>{$item.send_fee}</td>
                    <td>{$item.discount_fee}</td>
                    <td>
                        {$item.order_money}
                        {if $item.refund_money gt 0}
                        (已退款{$item.refund_money}元)
                        {/if}
                    </td>
                    <td>{$item.send_time}</td>
                    <td>{$item.sure_time}</td>
                    <td class="td-manage">
                        {if $item.order_status eq 0 && $item.is_trash eq 0 && (session("role_id") == 1 || session("role_id") == 14)}
                        <a style="text-decoration:none" class="ml-5" onClick="order_pay('{$item.order_no}')"
                           href="javascript:;" title="线下付款">
                            <i class="Hui-iconfont Hui-iconfont-duigou"></i>线下付款
                        </a>
                        {/if}

                        {if $item.order_status eq 0 && $item.is_trash eq 0}
                        <a style="text-decoration:none" class="ml-5" onClick="order_trash('{$item.order_no}', this, 1)"
                           href="javascript:;" title="订单回收">
                            <i class="Hui-iconfont Hui-iconfont-del2"></i>订单回收
                        </a>
                        {/if}
                        {if $item.is_trash eq 1}
                        <a style="text-decoration:none" class="ml-5" onClick="order_trash('{$item.order_no}', this, 0)"
                           href="javascript:;" title="撤销回收">
                            <i class="Hui-iconfont Hui-iconfont-del2"></i>撤销回收
                        </a>
                        {/if}
                        {if $item.order_status eq 1 and $item.is_send eq 0}
                        <a style="text-decoration:none" class="ml-5" onClick="order_send('{$item.order_no}')"
                           href="javascript:;" title="发货">
                            <i class="Hui-iconfont">&#xe623;</i>发货
                        </a>
                        {/if}
                        {if $item.order_status eq 2 and $item.is_send eq 1}
                        <a style="text-decoration:none" class="ml-5" onClick="send_sure('{$item.order_no}')"
                           href="javascript:;" title="提醒收货">
                            <i class="Hui-iconfont">&#xe623;</i>提醒收货
                        </a>
                        {/if}
                        {if $item.order_status eq 0}
                        <a style="text-decoration:none" class="ml-5" onClick="send_fee_change('{$item.id}')"
                           href="javascript:;" title="运费调整">
                            <i class="Hui-iconfont">&#xe623;</i>运费调整
                        </a>
                        {/if}
                        <a style="text-decoration:none" class="ml-5" onClick="order_detail('{$item.id}')"
                           href="javascript:;" title="订单详情">
                            <i class="Hui-iconfont">&#xe623;</i>订单详情
                        </a>
                        {if $item.is_apply_refund eq 1}
                        <a style="text-decoration:none" class="ml-5" onClick="order_refund('{$item.order_no}')"
                           href="javascript:;" title="退货处理详情">
                            <i class="Hui-iconfont">&#xe623;</i>退货处理详情
                        </a>
                        <a style="text-decoration:none" class="ml-5" onClick="ok_refund('{$item.order_no}', this)"
                           href="javascript:;" title="已做线下退款处理">
                            <i class="Hui-iconfont">&#xe623;</i>已做线下退款处理
                        </a>
                        <a style="text-decoration:none" class="ml-5" onClick="order_refuse('{$item.order_no}', this)"
                           href="javascript:;" title="取消退货">
                            <i class="Hui-iconfont">&#xe623;</i>取消退货
                        </a>
                        {/if}
                        {if $item.pay_status eq 1}

                        <a style="text-decoration:none" class="ml-5" data-status="1" onClick="order_check('{$item.order_no}', this)"
                           href="javascript:;" title="结算详情">
                            <i class="Hui-iconfont Hui-iconfont-list"></i>查看结算详情
                        </a>
                        {/if}
                    </td>
                </tr>
                {/foreach}
                </tbody>
            </table>
            {$list->render()}
        </div>
    </div>

{include file='pub/footer'/}
<script type="text/javascript">
    //线下付款
    function order_pay(order_no) {
        layer.confirm("确定当前订单已经线下支付?", function () {
            layer_show("添加支付信息", "{:url('addPayInfo')}?order_no="+order_no);
        });
    }
    function send_sure(order_no) {

        layer.confirm("确定发送收货提醒?", function () {
            $.post("{:url('send_sure_msg')}", {order_no:order_no}, function (res) {
                if(res.code == 1){
                    layer.msg("发送成功");
                }else{
                    layer.msg(res.msg);
                }
            });
        });
    }

    function order_trash(order_no, o, status) {
        var msg = status==1?"确定回收此订单？":"确定撤销回收此订单？";
        layer.confirm(msg, function () {
            $.post('{:url("order_trash")}', {order_no:order_no, status:status}, function (res) {
                if(res.code == 1){
                    $(o).parent().parent().remove();
                }
                layer.msg(res.msg);
            });
        })
    }




    function order_check(order_no, o){
        var status = $(o).data("status");
        if(status == 1){
            layer_show('订单结算详情', "{:url('Order/checkDetail')}?order_no="+order_no);
        }else{
            $.post('{:url("order_check")}', {order_no:order_no, status:status}, function (res) {
                if(res.code == 1){
                    if(status == 1){
                        $(o).data("status", 3);
                        $(o).next().remove();
                        $(o).html("撤销订单结算");
                    }else{
                        $(o).unbind();
                        $(o).html("已取消结算");
                    }
                }
            });
        }
    }

    function order_first(order_no, o){
        var status = $(o).data("status");
        $.post('{:url("order_first")}', {order_no:order_no, status:status}, function (res) {
            if(res.code == 1){
                if(status == 1){
                    $(o).data("status", 3);
                    $(o).next().remove();
                    $(o).html("首单撤销结算");
                }else{
                    $(o).unbind();
                    $(o).html("已取消首单结算");
                }
            }
        });
    }



    // $('.table-sort').dataTable({
    //     "aaSorting": [[1, "desc"]],//默认第几个排序
    //     "bStateSave": true,//状态保存
    //     "aoColumnDefs": [
    //         {"orderable": false, "aTargets": [13]}// 制定列不参与排序
    //     ],
    // });

    function ok_refund(order_no, o){
        layer.prompt({
            formType: 0,
            value: '',
            title: "确认订单已线下退款？请填写退款金额"
        }, function (val1, index) {
        	
            var val = parseFloat(val1);
            if(isNaN(val) || val<=0){
                layer.msg("请输入有效金额");
                return;
            }
                $.post("{:url('Order/ok_refund')}", {order_no: order_no, money: val},function (res) {
                    if(res.code == 1){
                        $(o).prev().remove();
                        $(o).next().remove();
                        $(o).remove();
                    }
                    layer.msg(res.msg);
                    layer.close(index);
                });
            
        })
    }
    
    function order_refuse(order_no, o){
        layer.confirm("确认取消退货?", function () {
            $.post("{:url('Order/order_refuse')}", {order_no:order_no}, function (res) {
                if(res.code == 1){
                    $(o).prev().remove();
                    $(o).prev().remove();
                    $(o).remove();
                }
                layer.msg(res.msg);
            });
        });
    }
    //下载订单
    function downloadOrder() {
        var start = $.trim($("#datemin").val());
        var end = $.trim($("#datemax").val());
        if(start == "" || end == ""){
            layer.alert("请选择订单生成时间段后再下载");
            return false;
        }
        var down_con = JSON.stringify($("form").serializeArray());
        var downWin = window.open("{:url('downloadExcel')}?key="+down_con);
        downWin.onload = function () {
            downWin.close();
        }
    }


    //订单详情
    function order_detail(order_id) {
        layer_show('订单详情', "{:url('Order/order_detail')}?order_id=" + order_id);

    }

    //订单配送
    function order_send(order_no) {
        layer_show('订单详情', '{:url("orderSend")}?order_no='+order_no);
    }
    //运费调整
    function send_fee_change(order_id){
        layer_show('运费调整', '{:url("sendFeeChange")}?order_id='+order_id);
    }
    //退货处理
    function order_refund(order_no){
        layer_show('退货处理', '{:url("orderRefund")}?order_no='+order_no);
    }

</script>
</body>
</html>